package cn.tedu.blackhorse.controller;

import cn.tedu.blackhorse.pojo.dto.OrderAddNewDTO;
import cn.tedu.blackhorse.pojo.vo.OrderListItemVO;
import cn.tedu.blackhorse.service.IOrderService;
import cn.tedu.blackhorse.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@Api(tags = "订单管理")
@Slf4j
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @PostMapping("/addNew")
    @ApiOperation("新增订单")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(OrderAddNewDTO orderAddNewDTO){
        log.debug("开始处理新增订单的业务");
        orderService.insertOrder(orderAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("删除订单")
    @ApiOperationSupport(order = 200)
    public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理删除订单的业务");
        orderService.deleteOrder(id);
        return JsonResult.ok();
    }

    @GetMapping("/")
    @ApiOperation("订单列表")
    @ApiOperationSupport(order = 300)
    public JsonResult<List<OrderListItemVO>> list(){
        log.debug("开始处理查询订单列表的业务");
        List<OrderListItemVO> list = orderService.list();
        return JsonResult.ok(list);
    }


}
